package com.umer.pinban.scan.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.common.ui.recycleview.adapter.RecyclerviewBasicAdapter;
import com.common.ui.recycleview.base.ViewHolder;
import com.common.ui.recycleview.listener.OptListener;
import com.common.utils.Constants;
import com.common.utils.GlideUtils;
import com.umer.pinban.R;
import com.umer.pinban.bean.customer.ScanCustomerProjectList;
import java.util.List;

public class ScanCustomerProjectYiJingGouMaiAdapter extends RecyclerviewBasicAdapter<ScanCustomerProjectList> {

    private OptListener optListener;

    public ScanCustomerProjectYiJingGouMaiAdapter(Context context, List<ScanCustomerProjectList> datas, int layoutId,
                                                  OptListener optListener) {
        super(context, datas, layoutId);
        this.optListener = optListener;
    }

    @Override
    public void convert(ViewHolder holder, final ScanCustomerProjectList scanCustomerProjectList, final int position) {
        TextView tv_name = holder.getView(R.id.tv_name);
        LinearLayout select_jishi = holder.getView(R.id.linear_select_jishi);
        ImageView imageView =  holder.getView(R.id.iv);
        TextView tv1 =  holder.getView(R.id.tv1);
        TextView tv2 =  holder.getView(R.id.tv2);
        TextView tv3 =  holder.getView(R.id.tv3);
        TextView tv4 =  holder.getView(R.id.tv4);
        tv1.setText(scanCustomerProjectList.getName());

        int useType = scanCustomerProjectList.getUseType();

        //1不限制次数 0限制次数
        if(useType == 1){
            tv2.setVisibility(View.VISIBLE);
            tv2.setText("不限次数");

            tv3.setVisibility(View.VISIBLE);
            String txt = scanCustomerProjectList.getUseTime();
            if(txt!=null && !txt.equals("null")&& !txt.equals("")){
                int month = Integer.valueOf(txt);
                if(month<=1){
                    tv3.setText("到期日期:"+ scanCustomerProjectList.getUseTimeDate());
                }else {
                    tv3.setText("到期日期:"+ month+"个月");
                }
            }else
            {
                tv3.setText("到期日期:"+ scanCustomerProjectList.getUseTimeDate());
            }

            tv4.setVisibility(View.GONE);
        }else {

            if(scanCustomerProjectList.getUseTimeDate()!=null && !scanCustomerProjectList.getUseTimeDate().equals("null")
                    && !scanCustomerProjectList.getUseTimeDate().equals("")){
                tv2.setVisibility(View.VISIBLE);
                tv2.setText("月到期日:"+ scanCustomerProjectList.getUseTimeDate());
            }else {
                tv2.setVisibility(View.GONE);
            }

            tv3.setVisibility(View.VISIBLE);
            tv3.setText("剩余: "+scanCustomerProjectList.getUseNum()+"次");

            tv4.setVisibility(View.GONE);
        }

        TextView tv_jian =  holder.getView(R.id.tv_jian);
        TextView tv_jia =  holder.getView(R.id.tv_jia);
        TextView tv_result =  holder.getView(R.id.tv_result);
        tv_result.setText(""+scanCustomerProjectList.getCount());
        String name = scanCustomerProjectList.getPersonnelName();
        if(TextUtils.isEmpty(name)){
            tv_name.setText("选择技师");
        }else {
            tv_name.setText(name);
        }
        String path = scanCustomerProjectList.getFilePath();
        GlideUtils.getInstance().loadImageView(context,Constants.IP_PORT_DEFAULT_PICTURE+path,imageView);
        tv_jian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            optListener.onOptClick(v,position);
            }
        });
        tv_jia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,position);
            }
        });
        select_jishi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,position);
            }
        });
    }
}
